package sg4c.frontend;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageCaptureGraphicFrontend extends GraphicsFrontend {
    private final String storePathPrefix;
    private int imageCount=0;

    public ImageCaptureGraphicFrontend(String exepath, String path) throws IOException {
        super(exepath);
        this.storePathPrefix = path;
    }

    @Override
    public void draw(Graphics g) {
        try {
            super.draw(g);
            Image img = getImage();
            String path = String.format("%s%d.jpg", storePathPrefix, imageCount++);
            ImageIO.write((RenderedImage) img, "JPG", new File(path));
        } catch (IOException ex) {
            ex.printStackTrace();
            System.exit(1);
        }

    }
}
